package com.melesta.payment;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.os.Handler;
import android.widget.Toast;
import com.melesta.engine.EngineActivity;
import com.melesta.engine.EngineActivity.ActivityTickListener;
import com.melesta.engine.R.raw;
import com.melesta.engine.R.string;
import com.melesta.expansions.ActivityState;
import com.melesta.expansions.IEngineExpansion;
import com.melesta.payment.amazon.PaymentSystem;
import com.melesta.payment.inapp3.InAppResponse;
import com.melesta.payment.inapp3.InAppResponse.Status;
import com.melesta.payment.inapp3.InAppSystem;
import com.melesta.payment.interfaces.IListener;
import com.melesta.payment.listeners.ListenersMixer;
import com.melesta.payment.listeners.NativeListener;
import com.tapjoy.TapjoyLog;

public class PaymentExpansion
  implements IEngineExpansion
{
  private IListener defListener;

  public void onActivityResult(Context paramContext, int paramInt1, int paramInt2, Intent paramIntent)
  {
    PaymentManager.getInstance().onActivityResult(paramContext, paramInt1, paramInt2, paramIntent);
  }

  public void onActivitySateChange(ActivityState paramActivityState, final Context paramContext, Handler paramHandler)
  {
    boolean bool = true;
    PaymentManager localPaymentManager = PaymentManager.getInstance();
    if ((paramContext != null) && (this.defListener == null))
    {
      IListener[] arrayOfIListener = new IListener[2];
      arrayOfIListener[0] = new NativeListener();
      arrayOfIListener[bool] = new IListener()
      {
        public void onCancel(String paramAnonymousString)
        {
        }

        public void onError(String paramAnonymousString1, int paramAnonymousInt, String paramAnonymousString2)
        {
        }

        public void onPurchase(String paramAnonymousString, int paramAnonymousInt, long paramAnonymousLong)
        {
          if (paramAnonymousInt == 0)
            return;
          Resources localResources = paramContext.getResources();
          int i = localResources.getIdentifier(paramAnonymousString, "string", paramContext.getPackageName());
          if (i == 0)
            i = R.string.DefaultPurchase;
          Object[] arrayOfObject = new Object[1];
          arrayOfObject[0] = Integer.valueOf(paramAnonymousInt);
          String str = localResources.getString(i, arrayOfObject);
          Toast.makeText(paramContext, str, 0).show();
        }

        public void onRefund(String paramAnonymousString)
        {
        }

        public void onSent(String paramAnonymousString)
        {
        }

        public void updateSkuDetails(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3)
        {
        }
      };
      this.defListener = new ListenersMixer(arrayOfIListener);
    }
    switch (3.$SwitchMap$com$melesta$expansions$ActivityState[paramActivityState.ordinal()])
    {
    case 5:
    case 6:
    case 7:
    case 8:
    default:
      return;
    case 1:
      if ((0x2 & paramContext.getApplicationInfo().flags) != 0);
      while (true)
      {
        TapjoyLog.enableLogging(bool);
        localPaymentManager.addSystem(new InAppSystem().setDefaultListener(this.defListener));
        localPaymentManager.addSystem(new PaymentSystem().setDefaultListener(this.defListener));
        localPaymentManager.load(paramContext.getResources().openRawResource(R.raw.payment));
        localPaymentManager.onCreate(paramContext, paramHandler);
        EngineActivity.getInstance().addTickListener(new EngineActivity.ActivityTickListener()
        {
          public void onBeginTick()
          {
          }

          public void onEndTick()
          {
            PaymentManager.tryProcess();
          }
        });
        return;
        bool = false;
      }
    case 2:
      localPaymentManager.onDestroy(paramContext, paramHandler);
      return;
    case 3:
      localPaymentManager.onStart(paramContext, paramHandler);
      return;
    case 4:
    }
    localPaymentManager.onStop(paramContext, paramHandler);
  }

  public void onAddExpansion()
  {
  }

  public void onRemoveExpansion()
  {
  }

  public void resendTransaction(String paramString, int paramInt, long paramLong)
  {
    InAppResponse localInAppResponse = new InAppResponse().setName(paramString).setStatus(InAppResponse.Status.PURCHASED).setCountPerItem(paramInt).setListener(this.defListener);
    localInAppResponse.setInternalId(paramLong);
    PaymentManager.getInstance().postResponse(localInAppResponse);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.melesta.payment.PaymentExpansion
 * JD-Core Version:    0.6.2
 */